<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>选择身份</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

</head>
<body>
<div v-cloak id="app" >
    <div  v-for="(member,index) in members" style="background-color:#ffffff">
        <div class="changeMember-single" v-myclick="[member.member_id, changeMember]">
          <div class="singleleft"><img :src="member.portrait ? member.portrait : '../../image/portrait_moren.png' "></div>
          <div class="singleright">{{member.nickname}}（{{member.is_level_active == '0' ? member.disabled_name : member.name}}）</div>
        </div>
    </div>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>

    var members,
        vm;
    apiready = function () {
        MNActionButton = api.require('PIActionButton');
        wx = api.require('wx');
        showProgress();
        setBSImg();
        new Vue({
            el: '#blank'
        });

        var data = {
            member_id: getPrefs('member_id')
        };
        var callback = function (ret) {
            members = ret.content;
            initApp();
            api.parseTapmode();
        };
        pinet.post(URL.getMembers, data, callback);
        api.addEventListener({
            name: 'addmember'
        }, function () {
            window.location.reload();
        });
        addListeners();
        setRefreshHeaderInfo(refresh);
    };

    function refresh() {
        var data = {
            member_id: getPrefs('member_id')
        };
        var callback = function (ret) {
            members = ret.content;
            if (vm) {
                vm.members = members;
            }else{
                initApp();
                api.parseTapmode();
            }
            api.refreshHeaderLoadDone();
        };
        var errback = function () {
            api.refreshHeaderLoadDone();
        };
        pinet.post(URL.getMembers, data, callback, errback);
        addListeners();
    }
    function initApp() {
        vm =  new Vue({
            el: '#app',
            data: {
                members: members,
                imgPath: '../../image/',
            },
            methods: {
                changeMember: function (member_id) {
                    closeWin('user2');
                    closeWin('index');
                    showProgress();
                    var data = {
                        member_id: member_id
                    };
                    var callback = function (ret) {
                        var user = ret.content;
                        setPrefs('user', user);
                        setPrefs('member_id', user.member_id);
                        if(user.member_type == '4'||user.member_type == '3') {
                            openWin('user2');
                        }else{
                            openWin('../../index', {to:4,fromChangeUser:true});
                        }
                    };
                    pinet.post(URL.getUserinfo, data, callback);

                },
            }
        })
    }
    function makeprofit(){
      if (!getPrefs('token')) {
          reLogin();
          return;
      }
      openWin('makeprofit');
    }

    function addListeners() {
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });
        api.addEventListener({
            name: 'addmember'
        }, function () {
            window.location.reload();
        });
        api.addEventListener({
            name: 'reLogin'
        }, refresh);
        api.addEventListener({
            name: 'viewdisappear'
        }, function () {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function () {
            onPageEnd();
            api.closeWin();
        });
    }

</script>
</html>
